/* @formatter:off
 * Copyright (c) 2011 Lucas <lucas03093@gmail.com>
 * 
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
/* @formatter:on */

package nu.korkad.daytracker.alertdialog;

import nu.korkad.daytracker.R;
import nu.korkad.daytracker.info.AppInfo;
import android.app.AlertDialog;
import android.content.Context;
import android.text.SpannableString;
import android.text.util.Linkify;
import android.widget.TextView;

public class About
{
    /**
     * Creates a dialog (popup).
     * 
     * @param context
     * @param aboutText
     *            String
     * @param buttonText
     *            String
     * @return AlertDialog
     */
    public static AlertDialog create(Context context, String aboutText, String buttonText)
    {
        // Version info
        String aboutTitle = String
                .format(context.getString(R.string.dialog_about_text_title) + " %s", context.getString(R.string.app_name));
        String versionString = String
                .format(context.getString(R.string.dialog_about_text_version) + " %s", AppInfo.getVersionName(context));
        
        // Set text and make links clickable
        final TextView message = new TextView(context);
        final SpannableString s = new SpannableString(aboutText);
        
        // Set some padding
        message.setPadding(5, 5, 5, 5);
        
        // Set the dialog text
        message.setText(versionString + "\n\n" + s);
        
        // Turn web addresses to links
        Linkify.addLinks(message, Linkify.ALL);
        
        return new AlertDialog.Builder(context).setTitle(aboutTitle).setCancelable(true).setIcon(R.drawable.icon)
                .setPositiveButton(buttonText, null).setView(message).create();
    }
}
